﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Smt.Asm.Api.Model.Request;
using System.Text;

namespace Smt.Asm.Api.Helper
{
    public class SessionExtHelper
    {
        /// <summary>
        /// 获取系统6个字段的SQL形式
        /// </summary>
        /// <param name="sTableName">表名</param>
        /// <returns>
        ///    索引0: insert 语句的片段
        ///    索引1: value 值片段
        /// </returns>
        public static string[] GetSysFieldSQL(string sTableName, BaseReq oLgUser)
        {
            string[] sRetSQL = new string[2];
            if (null!=oLgUser)
            {
                StringBuilder sbInsert = new StringBuilder();
                StringBuilder sbValue = new StringBuilder();
                sbInsert.Append(sTableName).Append("_9990,").Append(sTableName).Append("_9991,");
                sbInsert.Append(sTableName).Append("_9992,").Append(sTableName).Append("_9993,");
                sbInsert.Append(sTableName).Append("_9994,").Append(sTableName).Append("_9995");

                //LoginUser oLgUser = null;
                //if (Smt.Utils.Common.FrameType == "BS")
                //{
                //    oLgUser = (LoginUser)HttpContext.Current.Session["LogUserInfo"];
                //}
                //else
                //{
                //    oLgUser = Smt.Utils.Common.MsLoginUser;
                //}

                //string sOrganId = (oLgUser.OrganId == "") ? "null" : oLgUser.OrganId;
                string sOrganId = "1";
                string sDeptId = (oLgUser.DeptId == "") ? "null" : oLgUser.DeptId;
                string sPosId = (oLgUser.PosId == "") ? "null" : oLgUser.PosId;
                //string sClassId = (oLgUser.ClassId == "") ? "null" : oLgUser.ClassId;
                string sClassId ="null";

                sbValue.Append(sOrganId).Append(",").Append(sDeptId).Append(",");
                sbValue.Append(sPosId).Append(",").Append(sClassId).Append(",");
                sbValue.Append(oLgUser.UserId).Append(",'").Append(DateTime.Now.ToString("yyyy-MM-dd HH:mm")).Append("'");
                oLgUser = null;

                sRetSQL[0] = sbInsert.ToString();
                sRetSQL[1] = sbValue.ToString(); 
            }
            else
            {
                sRetSQL[0] = "''";
                sRetSQL[1] = "''";
            }
            return sRetSQL;
        }
    }
}